package com.alphathink.deliveryassist.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.AlphaThink.DeliveryAssist.R;
import com.alphathink.deliveryassist.eneity.ContactBean;

public class MessageListViewAdapter extends BaseAdapter {
	private ArrayList<ContactBean> listData = null;
	private Context context = null;

	public ArrayList<ContactBean> getListData() {
		return listData;
	}

	public void setListData(ArrayList<ContactBean> listData) {
		this.listData = listData;
	}

	/*
	 * 构造函数
	 */
	public MessageListViewAdapter(ArrayList<ContactBean> list, Context context) {
		super();
		System.out
				.println("MessageListViewAdapter35---------------------------------------");
		this.listData = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		System.out
				.println("MessageListViewAdapter53---------------------------------------");

		ViewHolder holder;
		if (convertView == null) {
			// 将item与convertVIew帮顶
			LayoutInflater inflater = LayoutInflater.from(this.context);
			convertView = inflater.inflate(R.layout.phone_listview, null);
			holder = new ViewHolder();
			holder.nameTextView = (TextView) convertView
					.findViewById(R.id.phone_listview_TextViewName);
			holder.addressTextView = (TextView) convertView
					.findViewById(R.id.phone_listview_TextViewAddress);
			holder.numTextView = (TextView) convertView
					.findViewById(R.id.phone_listview_TextViewNum);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		// 存入后台传来的信息
		ContactBean contactModel = listData.get(position);

		System.out.println("--------------------------"
				+ contactModel.getContactName());

		Log.e("数据渲染", "--------数据地址:" + contactModel.getContactAddress());
		holder.nameTextView.setText(contactModel.getContactName());
		holder.addressTextView.setText(contactModel.getContactAddress());
		holder.numTextView.setText(contactModel.getContactNum());
		return convertView;
	}

	class ViewHolder {
		private TextView nameTextView;
		private TextView addressTextView;
		private TextView numTextView;
	}

}